#!/usr/bin/python3
# -*- coding: UTF-8 -*-

# dict迭代
d = {'name' : 'Jack', 'age' : 22, 'job' : 'actor'}
for key in d:
    print(key)

for v in d.values():
    print(v)

for k,v in d.items():
    print(k, ':', v)

# for in 循环迭代不需要下标，可以迭代list、tuple、字符串
for v in '28fghj':
    print(v)

# 通过collections模块的Iterable类型判断一个对象是不是一个可迭代对象

from collections import Iterable
print(isinstance('abh', Iterable))
print(isinstance(123, Iterable))

# 类似java的索引迭代
for i, v in enumerate(['a', 'b', 'c']):
    print(i, v)

# for循环里，同时引用了两个变量，在Python里是很常见的
for x, y in [(1,7), (2, 8), (3, 9)]:
    print(x, y)

def g():
    yield 1
    yield 2
    yield 3
print('Iterable? g():', isinstance(g(), Iterable))